package com.genzou.replacer

class FileReplacerTests extends GroovyTestCase {
    
    def replacer = new FileReplacer()
    
    void setUp(){
        //            def doBackup = ""
        //    def doNotInSubdirectories = ""
        //    def enabled = ""
        //    def ignoreCase = ""
        //    def ignoreDotFile = ""
        //    def useRegexp = ""
        //    def dir = ""
        //    def encoding = ""
        //    def excludes = ""
        //    def includes = ""
        //    def token = ""
        //    def replace = ""
    }
    
    final def S = File.separator
    void testCommonFilterToFile() {
        replacer.with{
            ignoreDotFile = true
            includes = ""
            excludes = ""
            assertFalse COMMON_FILTER([file:false])
        }
    }
    
    def dummyFile = { params ->
        [file:params, path:params.path, name:new File(params.path).name]
    }
    
    void testCommonFilter_ignoreDotFileTrue() {
        replacer.with{
            ignoreDotFile = true
            includes = ""
            excludes = ""
            assertTrue COMMON_FILTER(dummyFile(file:false, path:"${S}aaa${S}bbb${S}ccc${S}notdotfile"))
            assertFalse COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}ccc${S}.dotfile"))
            assertFalse COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}.test${S}normalfile"))
        }
    }
    
    void testCommonFilter_ignoreDotFileFalse() {
        
        replacer.with{
            ignoreDotFile = false
            includes = ""
            excludes = ""
            assertTrue COMMON_FILTER(dummyFile(file:false, path:"${S}aaa${S}bbb${S}ccc${S}notdotfile"))
            assertTrue COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}ccc${S}.dotfile"))
            assertTrue COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}.test${S}normalfile"))
        }
    }
    
    void testCommonFilter_includes() {
        replacer.with{
            ignoreDotFile = true
            includes = "ccc"
            excludes = ""
            assertFalse COMMON_FILTER(dummyFile(file:false, path:"${S}aaa${S}bbb${S}ccc${S}testfile"))
            assertFalse COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}ccc${S}.dotfile"))
            assertFalse COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}.test${S}normalcccfile"))
            assertTrue COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}test${S}normalcccfile"))
        }
    }
    
    void testCommonFilter_includesAndExcludes() {
        replacer.with{
            includes = "XX"
            excludes = "Xf"
            assertFalse COMMON_FILTER(dummyFile(file:true, path:"${S}aaa${S}bbb${S}ccc${S}normalXXfile"))
        }
    }
}
